package atguigu.retrofit;

import com.squareup.okhttp.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

import java.io.IOException;

public class Demo {

    public static void main(String[] args) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://localhost:3002/")
                .build();
        UserApi mApi = retrofit.create(UserApi.class);

        Call<ResponseBody> news = mApi.getUsers();
        news.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody body = response.body();
                try {
                    byte[] bytes = body.bytes();
                    String info = new String(bytes);
                    System.out.println(info);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }

            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {

            }
        });
    }
}
